package com.irdstudio.efp.report.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.report.service.dao.ZxbsLoanRepayDetailDao;
import com.irdstudio.efp.report.service.domain.ZxbsLoanRepayDetail;
import com.irdstudio.efp.report.service.facade.ZxbsLoanRepayDetailService;
import com.irdstudio.efp.report.service.vo.ZxbsLoanRepayDetailVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 服务实现
 *
 * @author gcb
 * @date 2020-07-28
 */
@Service("zxbsLoanRepayDetailService")
public class ZxbsLoanRepayDetailServiceImpl implements ZxbsLoanRepayDetailService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(ZxbsLoanRepayDetailServiceImpl.class);

    @Autowired
    private ZxbsLoanRepayDetailDao zxbsLoanRepayDetailDao;

    /**
     * 新增数据
     *
     * @param zxbsLoanRepayDetailVo
     * @return
     */
    @Override
    public int insert(ZxbsLoanRepayDetailVO zxbsLoanRepayDetailVo) {
        logger.debug("当前新增数据为:" + zxbsLoanRepayDetailVo.toString());
        int num = 0;
        try {
            ZxbsLoanRepayDetail zxbsLoanRepayDetail = new ZxbsLoanRepayDetail();
            beanCopy(zxbsLoanRepayDetailVo, zxbsLoanRepayDetail);
            num = zxbsLoanRepayDetailDao.insert(zxbsLoanRepayDetail);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param zxbsLoanRepayDetailVo
     * @return
     */
    @Override
    public int deleteByPk(ZxbsLoanRepayDetailVO zxbsLoanRepayDetailVo) {
        logger.debug("当前删除数据条件为:" + zxbsLoanRepayDetailVo);
        int num = 0;
        try {
            ZxbsLoanRepayDetail zxbsLoanRepayDetail = new ZxbsLoanRepayDetail();
            beanCopy(zxbsLoanRepayDetailVo, zxbsLoanRepayDetail);
            num = zxbsLoanRepayDetailDao.deleteByPk(zxbsLoanRepayDetail);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsLoanRepayDetailVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param zxbsLoanRepayDetailVo
     * @return
     */
    @Override
    public int updateByPk(ZxbsLoanRepayDetailVO zxbsLoanRepayDetailVo) {
        logger.debug("当前修改数据为:" + zxbsLoanRepayDetailVo.toString());
        int num = 0;
        try {
            ZxbsLoanRepayDetail zxbsLoanRepayDetail = new ZxbsLoanRepayDetail();
            beanCopy(zxbsLoanRepayDetailVo, zxbsLoanRepayDetail);
            num = zxbsLoanRepayDetailDao.updateByPk(zxbsLoanRepayDetail);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsLoanRepayDetailVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inZxbsLoanRepayDetailVo
     * @return
     */
    @Override
    public ZxbsLoanRepayDetailVO queryByPk(ZxbsLoanRepayDetailVO inZxbsLoanRepayDetailVo) {
        logger.debug("当前查询参数信息为:" + inZxbsLoanRepayDetailVo);
        try {
            ZxbsLoanRepayDetail queryZxbsLoanRepayDetail = new ZxbsLoanRepayDetail();
            beanCopy(inZxbsLoanRepayDetailVo, queryZxbsLoanRepayDetail);
            ZxbsLoanRepayDetail queryRslZxbsLoanRepayDetail = zxbsLoanRepayDetailDao.queryByPk(queryZxbsLoanRepayDetail);
            if (Objects.nonNull(queryRslZxbsLoanRepayDetail)) {
                return beanCopy(queryRslZxbsLoanRepayDetail, new ZxbsLoanRepayDetailVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int insertOrUpdate(List<ZxbsLoanRepayDetailVO> list) throws Exception {
        return zxbsLoanRepayDetailDao.insertOrUpdate((List<ZxbsLoanRepayDetail>) beansCopy(list, ZxbsLoanRepayDetail.class));
    }

    @Override
    public List<ZxbsLoanRepayDetailVO> queryByRpyNo(List<String> setlSeqs) throws Exception {

        return (List<ZxbsLoanRepayDetailVO>) beansCopy(this.zxbsLoanRepayDetailDao.queryByRpyNo(setlSeqs),ZxbsLoanRepayDetailVO.class);
    }
}
